//
//  NetSession.h
//  FreeNet
//
//  Created by cc on 12-7-5.
//  Copyright (c) 2012年 cc. All rights reserved.
//

#ifndef _FREENET_NETSESSION_H_CC_
#define _FREENET_NETSESSION_H_CC_

#include "NetDefine.h"
#include "NetUtil.h"

namespace FreeNet {

    class CEpoll
    {
    public:
        CEpoll(const int max, const char* ip, const int port, const eNetMode mode = NET_TCP) ;
        ~CEpoll() ;

    public:
        int wait(const int timeout = -1) ;
        void destroy() ;
//    private:
        bool Ctl(const int op, const int fd) ;

    public:
        epoll_event* remoteEvents ;
        sNetInfo     localInfo ;
        epoll_event  localEvent ;
//    private:
        int          remoteCount ;
        int          epollFD ;
    } ;

    extern int connectServer(const char* ip, const int port, const eNetMode mode, NET_CALLBACK cb) ;
    extern int disconnectSession(const int fd, NET_CALLBACK cb) ;
    extern size_t sendMessage(const void* data, const int len, const int fd, NET_CALLBACK cb) ;
    extern size_t recvMessage(void* data, size_t len, const int fd, NET_CALLBACK cb) ;
    extern size_t sendMessageTo(const char* ip, const int port, const void* data, const int len, NET_CALLBACK cb) ;
    extern size_t recvMessageFrom(const char* ip, const int port, void* data, size_t len, NET_CALLBACK cb) ;
}

#endif

























